from django.test import TestCase
from ..models import User
from tasks.models import Tasks
from django.urls import reverse
from tasks.services import initial_tasks
from django.test import Client


class UserRegisterViewTest(TestCase):

    def setUp(self):
        user = User.objects.create(email='testUser@email.com', password='12345678')
        self.client = Client()
        self.user = user

    def test_view_url_accessible_by_name(self):
        resp = self.client.get(reverse('account:register'))
        self.assertEqual(resp.status_code, 200)

    def test_view_url_exists_at_desired_location(self):
        resp = self.client.get('/registration/')
        self.assertEqual(resp.status_code, 200)

        self.assertTemplateUsed(resp, 'users/registration.html')

    def test_if_can_register_profile(self):
        self.client.post(reverse('account:register'), {
            'email': 'test1@test.com'
        })
        self.assertTrue(User.objects.filter(email='test1@test.com').exists())
        new_user = User.objects.get(email='test1@test.com')
        tasks = Tasks.objects.filter(owner=new_user)
        self.assertEqual(tasks.count(), 40)